package com.ss.android.action.a.c;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.Toast;

import com.ss.android.account.Spipe;
import com.ss.android.account.b.OnAccountRefreshListener;
import com.ss.android.account.model.SharePlatform;
import com.ss.android.account.o;
import com.ss.android.article.browser.R;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;

public abstract class BaseShareDialog extends Dialog implements OnAccountRefreshListener {
    final class WeakHandler extends Handler {
        private WeakReference<BaseShareDialog> ref;

        public WeakHandler(BaseShareDialog arg2) {
            this.ref = new WeakReference(arg2);
        }

        public final void handleMessage(Message message) {
            BaseShareDialog baseShareDialog = this.ref.get();
            if (baseShareDialog != null) {
                baseShareDialog.handleMessage(message);
            }
        }
    }

    public Context mContext;
    protected Spipe mSpipe;
    protected SharePlatform[] PlatformItems;
    protected Handler mHandler;
    private boolean e;
    private o f;

    public BaseShareDialog(Activity activity) {
        super(activity, R.style.ss_comment_panel);
        this.e = true;
        this.mHandler = new WeakHandler(this);
        this.a(activity);
    }

    protected void a(Activity arg2) {
        this.mContext = arg2;
        LayoutInflater.from(arg2);
        this.f = new o();
        this.setOwnerActivity(arg2);
    }

    public abstract int getLayoutId();

    protected void a(int arg4) {
        int v0;
        switch (arg4) {
            case 12: {
                v0 = R.string.ss_send_fail_no_connection;
                break;
            }
            case 14: {
                v0 = R.string.ss_send_fail_network_timeout;
                break;
            }
            case 15: {
                v0 = R.string.ss_send_fail_network_error;
                break;
            }
            case 105: {
                this.b();
                v0 = R.string.ss_send_fail_session_expire;
                break;
            }
            default: {
                v0 = R.string.ss_send_fail_unknown;
                break;
            }
        }

        Toast.makeText(this.getOwnerActivity(), v0, Toast.LENGTH_SHORT).show();
    }

    final void handleMessage(Message message) {
        if (this.e) {
            switch (message.what) {
                case 1009: {
                    this.b(message);
                    return;
                }
                case 1010: {
                    this.a(message.arg1);
                    return;
                }
            }

            return;


        }
    }

    final void b() {
        SharePlatform[] v2 = this.PlatformItems;
        int v3 = v2.length;
        int v0;
        for (v0 = 0; v0 < v3; ++v0) {
            v2[v0].mLogin = false;
        }
    }

    protected void b(Message arg4) {
        if (arg4.obj != null) {
            Toast.makeText(this.getOwnerActivity(), R.string.ss_send_success, Toast.LENGTH_SHORT).show();
        }
    }

    public void onAccountRefresh(boolean arg2, int arg3) {
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.requestWindowFeature(1);
        this.setContentView(this.getLayoutId());
        this.setCancelable(true);
        this.setCanceledOnTouchOutside(true);
        this.f.c = true;
        o v2 = this.f;
        v2.a = Spipe.inst();
        SharePlatform[] v0 = v2.a.c();
        if (v2.c) {
            ArrayList v3 = new ArrayList(Arrays.asList(((Object[]) v0)));
            int v1 = v3.size() - 1;
            while (v1 >= 0) {
                if ("qzone_sns".equals(((SharePlatform) v3.get(v1)).mName)) {
                    v3.remove(v1);
                } else {
                    --v1;
                    continue;
                }

                break;
            }

            v2.b = new SharePlatform[v3.size()];
            v2.b = (SharePlatform[]) v3.toArray(v2.b);
        } else {
            v2.b = v0;
        }

        this.mSpipe = this.f.a;
        Log.d("travis", "BaseShareDialog:::onCreate()   mSpipe=" + mSpipe);
        this.PlatformItems = this.mSpipe.c();
        this.mSpipe.addOnAccountRefreshListener(((OnAccountRefreshListener) this));
    }

    public void onStop() {
        if (((Activity) this.mContext).isFinishing()) {
            this.e = false;
        }
    }
}

